package order

import (
	"api/pb/order"
	"context"

	"api/internal/svc"
	"api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type GetOrderInfoLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewGetOrderInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetOrderInfoLogic {
	return &GetOrderInfoLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *GetOrderInfoLogic) GetOrderInfo(req *types.OrderIDRequest) (resp *types.Order, err error) {
	info, err := l.svcCtx.OrderRpc.GetOrderByID(l.ctx, &order.IDRequest{OrderId: req.OrderId})
	if err != nil {
		return nil, err
	}

	resp = &types.Order{
		UserId:      info.UserId,
		OrderId:     info.OrderId,
		OrderStatus: info.OrderStatus,
		OrderTotal:  info.OrderTotal,
		CreateTime:  info.CreateTime,
		UpdateTime:  info.UpdateTime,
		DeleteTime:  info.DeleteTime,
		Goods:       []types.OrderGood{},
	}
	return
}
